package com.talkweb.securitycamera.common.base.utils;

import ohos.app.Context;
import ohos.global.resource.*;

import java.io.IOException;

/**
 * @version 1.0.1
 * @description:资源文件工具
 * @program: security-camera
 * @Author xiaozhijun
 * @Date 2021/1/25 17:30
 */
public final class ResourceHelper {

    /**
     * 获取字符数据
     *
     * @param context
     * @param resourceId
     * @return
     */
    public static String[] getStringArray(Context context, int resourceId) {
        String[] resourceStringArray = new String[]{};
        Element element = null;
        try {
            ResourceManager resourceManager = context.getResourceManager();
            element = resourceManager.getElement(resourceId);
            resourceStringArray = element.getStringArray();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NotExistException e) {
            e.printStackTrace();
        } catch (WrongTypeException e) {
            e.printStackTrace();
        }
        return resourceStringArray;
    }

    /**
     * 获取字符串
     * @param context
     * @param resourceId
     * @return
     */
    public static String getString(Context context, int resourceId) {
        String resourceString = "";
        Element element = null;
        try {
            ResourceManager resourceManager = context.getResourceManager();
            element = resourceManager.getElement(resourceId);
            resourceString = element.getString();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NotExistException e) {
            e.printStackTrace();
        } catch (WrongTypeException e) {
            e.printStackTrace();
        }
        return resourceString;
    }

    /**
     * 获取Resource
     * @param context
     * @param resourceId
     * @return
     */
    public static Resource getResource(Context context, int resourceId) {
        Resource resource = null;
        try {
            ResourceManager resourceManager = context.getResourceManager();
            resource = resourceManager.getResource(resourceId);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NotExistException e) {
            e.printStackTrace();
        }
        return resource;
    }
}
